﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using Batman.Cache;
using Batman.Core;
using Batman.Jianbei.Forum.Core.ChatRoom;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace Batman.Jianbei.Forum.Services.ChatRoom
{
    public class RoomMaskQueryService : ApplicationService, ICacheWorkable
    {

        public IRepository<RoomMask, string> RoomMaskRepo { get; set; }

        /// <summary>
        /// 获取单个聊天室内指定用户的匿名身份
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public Mask GetMask(string roomId, string uid)
        {
            var roomMask = this.GetRoomMasks(roomId).FirstOrDefault(t => t.Uid == uid);
            return roomMask.Mask;
        }

        /// <summary>
        /// 获取房间内全部在线的的匿名身份
        /// </summary>
        /// <param name="roomId"></param>
        /// <returns></returns>
        public List<RoomMask> GetRoomMasks(string roomId)
        {
            var roomMasks = RoomMaskRepo.GetQuery().Include(t => t.Mask).Where(t => t.RoomId == roomId && t.IsInRoom).ToList();
            return roomMasks;
        }
    }
}
